import { Injectable,Type } from '@angular/core';

import { Logger } from './logger.service';
import { Hero } from './hero'

const HEROS=[
	new Hero("Captain American","Big breasts"),
	new Hero("Loki","Silver Throat"),
	new Hero("Black Widow","The best spy")
];

@Injectable()
export class BackendService{

	constructor(private logger: Logger){}

	getAll(type:Type<any>): PromiseLike<any[]> {
		if(type==Hero){
			return Promise.resolve<Hero[]>(HEROS);
		}
		let err=new Error('Cannot get object of this type');
		this.logger.error(err);
		throw err;
	}
}